﻿/*******************************************************************************
 * AAEngine
 * Copyright (c) 2010 Mike Jarosch
 *
 * Original source PushButton Engine:
 * Copyright (C) 2009 PushButton Labs, LLC
 * For more information see http://www.pushbuttonengine.com
 *
 * This file is licensed under the terms of the MIT license, which is included
 * in the "MIT License.txt" file at the root directory of this SDK.
 ******************************************************************************/

using System;
using AAEngine.Engine.Serialization;

namespace AAEngine.Engine.Entities
{
    /// <summary>
    /// Internal class used by Entity to service property lookups.
    /// </summary>
    internal sealed class PropertyInfo
    {
        public object PropertyParent = null;
        public string PropertyName = null;

        public object GetValue()
        {
            try
            {
                if (!String.IsNullOrEmpty(PropertyName))
                {
                    return TypeUtility.GetProperty(PropertyParent, PropertyName);
                }
                else
                {
                    return PropertyParent;
                }
            }
            catch (Exception)
            {
                return null;
            }
        }

        public void SetValue(object value)
        {
            TypeUtility.SetProperty(PropertyParent, PropertyName, value);
        }

        public void Clear()
        {
            PropertyName = null;
            PropertyParent = null;
        }
    }
}
